package progress.exa31_2;

import java.util.function.*;

public class FunctionStudy {

    public static void main(String[] args) {

        FunctionStudy functionStudy = new FunctionStudy();
        //无入参,出参lambda表达式
        functionStudy.runnableStudy(()->{
            System.out.println("使用Runnable的lambada表达式打印这句话的");
        });
        //无入参,有出参lambda表达式
        functionStudy.supplierStudy(()->{
            return "使用Supplier的lambada表达式打印这句话的";
        });
        //一个入参,无出参lambda表达式
        functionStudy.consumerStudy("consumerStudy",(s)->{
            if(s.contains("consumer")){
                System.out.println(s);
            }
        });
        //两个入参,无出参lambda表达式
        functionStudy.biConsumerStudy("BiConsumerStudy","two",(s,t)->{
            System.out.println(s+t);
        });
        //一个入参,有出参lambda表达式
        functionStudy.functionStudy("functionStudy",(s)->{
            return s+"test";
        });
        //两个入参,一个出参lambda表达式
        functionStudy.biFunctionStudy("bi","Function",(s,u)->{
            return s+u;
        });
        //一个入参，一个出参lambda表达式
        functionStudy.unaryOperatorStudy("s",(s)->{
            return s;
        });
        //两个入参，一个出参lambda表达式
        functionStudy.binaryOperatorStudy("binary","Operation",(s,v)->{
            return s+v;
        });
        //一个入参，指定boolean类型出参lambda表达式
        functionStudy.predicateStudy("isGood",(s)->{
            return s.contains("ood");
        });
        //两个入参，指定boolean类型出参lambda表达式
        functionStudy.biPredicateStudy("bi","Predicate",(t,u)->{
            if(t.equals("bi")&&u.contains("cate")){
                return true;
            }else
                return false;
        });
    }


    public void runnableStudy(Runnable runnable){
        runnable.run();
    }

    public void supplierStudy(Supplier<String> stringSupplier){
        System.out.println(stringSupplier.get());
    }

    public void consumerStudy(String param,Consumer<String> stringConsumer){
        stringConsumer.accept(param);
    }

    public void biConsumerStudy(String u, String t, BiConsumer<String,String> biConsumer){
        biConsumer.accept(u,t);
    }

    public void functionStudy(String t,Function<String,String> function){
        System.out.println(function.apply(t));
    }

    public void biFunctionStudy(String t, String u, BiFunction<String,String,String> biFunction){
        System.out.println(biFunction.apply(t,u));
    }

    public void unaryOperatorStudy(String s,UnaryOperator<String> unaryOperator){
        System.out.println(unaryOperator.apply(s));
    }

    public void binaryOperatorStudy(String s,String t,BinaryOperator<String> binaryOperator){
        System.out.println(binaryOperator.apply(s,t));
    }

    public void predicateStudy(String s,Predicate<String> predicate){
        if(predicate.test(s)){
            System.out.println("正确！！！！");
        }
    }

    public void biPredicateStudy(String t,String u,BiPredicate<String,String> biPredicate){
        if(biPredicate.test(t,u)){
            System.out.println("正确！！");
        }
    }


}
